<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>svg</title>
	</head>
	<body>
		<script type="text/javascript" src="./uni.webview.1.5.5.js"></script>
		<script type="text/javascript">
			function onReceiveSvg(svg) {
				svg2Png(svg).then(res => {
					uni.webView.postMessage({data: {png: res.png}})
				});
			};

			function svg2Png(svg) {
				const src = `data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(svg)))}`;
				const img = new Image();
				img.src = src;
				return new Promise((resolve, rej) => {
					img.onload = () => {
						const canvas = document.createElement('canvas');
						canvas.width = img.width * window.devicePixelRatio;
						canvas.height = img.height * window.devicePixelRatio;
						const context = canvas.getContext('2d');
						context.drawImage(img, 0, 0,canvas.width,canvas.height);
						const ImgBase64 = canvas.toDataURL('image/png');
						resolve({
							png: ImgBase64
						});
					};
				});
			};
			
			uni.webView.postMessage({data: {isInitialize: true}});
		</script>
	</body>
</html>